import { createElement, LinkHTMLAttributes, type FC } from 'react';
import classNames from 'classnames';

import { itemHeaderDefaultProps } from './defaultProps';
import type { ItemHeaderOptions } from './type';

export interface ItemHeaderProps extends ItemHeaderOptions, Omit<LinkHTMLAttributes<HTMLLinkElement>, 'as'> {}

const ItemHeader: FC<ItemHeaderProps> = (props) => {
  const { className, as, children, forwardedRef, ...itemHeaderProps } = props;

  return createElement(
    as!,
    { ref: forwardedRef, className: classNames('header', className), ...itemHeaderProps },
    children,
  );
};

ItemHeader.displayName = 'ItemHeader';
ItemHeader.defaultProps = itemHeaderDefaultProps;

export default ItemHeader;
